package com.tskj.leonsu.dao;

import com.alibaba.fastjson.JSONArray;
import com.tskj.leonsu.db.DbUtilitys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class SystemDAO {

    @Autowired
    private DbUtilitys dbUtilitys;

    public JSONArray getModuleList() {
        String sql = "select * from modules where route <> '' order by sortno";
        List<Map<String, Object>> list = dbUtilitys.execSQL(sql);
        return JSONArray.parseArray(JSONArray.toJSONString(list));
    }
    public void updateModuleStatus(String moduleId, boolean active) throws Exception {
        String sql = "update modules set isactive=? where id=?";
        dbUtilitys.execSQLWithTran(sql, active, moduleId);
    }

    public void updateModuleTime(String moduleId, String startTime, String endTime) throws Exception {
        String sql = "update modules set starttime=?, endtime=? where id=?";
        dbUtilitys.execSQLWithTran(sql, startTime, endTime, moduleId);
    }

    public void updateModuleName(String moduleId, String moduleName) throws Exception {
        String sql = "update modules set modulename=? where id=?";
        dbUtilitys.execSQLWithTran(sql, moduleName, moduleId);
    }

    public void updateModuleDesc(String moduleId, String desc) throws Exception {
        String sql = "update modules set desc=? where id=?";
        dbUtilitys.execSQLWithTran(sql, desc, moduleId);
    }
}
